import { Component, OnInit, Input, ViewChild, EventEmitter, Output } from '@angular/core';
import { HttpService } from 'lbf';
import { NzMessageService, NzModalService, NzModalRef } from 'ng-zorro-antd';
import { LbBztInfoComponent } from '../lb_bzt_info/lb_bzt_info.component';

@Component({
  selector: 'lb-bzt',
  templateUrl: './lb_bzt.component.html',
  styleUrls: ['./lb_bzt.component.less']
})
export class LbBztComponent implements OnInit {
  @Input() nzVisible = false;
  @Input() dataDAD069 = 0;
  @ViewChild('step', { static: true }) step: LbBztInfoComponent;

  showStepWindow = false;
  isShowInfo = false;

  modal: NzModalRef<LbBztInfoComponent, any>



  ngOnInit() {
    this.isShowInfo = false;
    this.initBzt();
  }

  initBzt() {
    this.lbs.lbservice('bzt_data', { DAD069: this.dataDAD069 }).then(resdata => {
      console.log(resdata);
      if (resdata.code >= 1) {
        this.step.stepsNodes = resdata.data;
      } else {
        this.msgSrv.error(resdata.errmsg);
      }
    });

  }

  createZxBzt(ln_dae001: number) {

    this.lbs.lbservice('bzt_data', { DAD069: this.dataDAD069, DAE001: ln_dae001 }).then(resdata => {
      console.log(resdata);
      if (resdata.code >= 1) {
        const stepsNodes = resdata.data;
        const ok = new EventEmitter<string>()

        this.modal = this.modalService.create({
          nzTitle: '步骤图',
          nzContent: LbBztInfoComponent,
          nzWidth: '1000px',
          nzBodyStyle: { height: '400px' },
          nzMaskClosable: false,
          nzComponentParams: {
            stepsNodes,
            ok
          },
          nzOkText: null,
        });
        ok.subscribe(res => {
          this.handleStepClick(res);

        })
      } else {
        this.msgSrv.error(resdata.errmsg);
      }
    });
  }

  handleStepClick(res: any) {
    const instance = this.modal.getContentComponent();
    if (res.type === '3') {
      instance.showHjInfo = false;
    }
    else {
      instance.showHjInfo = true;
      instance.hjInfo = res;
    }


  }

  handleClick(res: any) {
    // 如果是环节 则显示环节具体信息

    // 如果是子项，则弹窗显示子项环节
    if (res.type === '1') {
      this.step.showHjInfo = false;
      this.createZxBzt(parseInt(res.id));
    }
    // 开始、结束
    else if (res.type === '3') {
      this.step.showHjInfo = false;
    }
    else {
      this.step.showHjInfo = true;
      this.step.hjInfo = res;
    }




  }




  closeWindow() {
    this.showStepWindow = false;
  }




  InitData(value: number) {

    this.lbs.lbservice('ZSK_DATA', { DAD017: value }).then(resdata => {
      if (resdata.code >= 1) {
        // this.dataZsk = resdata.message.list[0];

      } else {

      }
    });
  }


  constructor(private lbs: HttpService,
    private modalService: NzModalService,
    public msgSrv: NzMessageService) { }
}
